﻿using RSModels.Data;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace RSDriverAndroid.Views
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class TaskView : ContentView
    {
        public TaskView(ObservableCollection<RSTask> rSTasks)
        {
            InitializeComponent();
            Tasks = rSTasks;
            TaskContentLabel.BindingContext = this;
            TaskContentLabel.SetBinding(Label.TextProperty, "TaskContent");
            Tasks.CollectionChanged += Tasks_CollectionChanged;
        }

        private void Tasks_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            if (Tasks == null || Tasks.Count == 0)
                TaskContent = "暂无";
            else
                TaskContent = Tasks[0].Content;
        }

        public ObservableCollection<RSTask> Tasks { get; set; }
        public string TaskContent { get; set; } = "暂无";

        private void Button_Clicked(object sender, EventArgs e)
        {
            Tasks.Add(new RSTask() { Content = "1" });
        }

        private void Button_Clicked_1(object sender, EventArgs e)
        {
            if (Tasks.Count > 0)
                Tasks.RemoveAt(0);
        }
    }
}